home *** CD-ROM | disk | FTP | other *** search
- *** 1.69 1992/03/22 21:57:30
- --- Changelo 1992/03/28 06:36:49
- ***************
- *** 2911,2913 ****
- --- 2911,2931 ----
- merge diff for atof
-
- ---------------------------- Patchlevel 78 ---------------------------
- + signal.c, console.c: alexander lehmann
- + fix for a bug where console i/o would get stuck when a interrupt
- + was caught and it occured when the input buffer was not empty.
- +
- +
- + fread.c, fwrite.c: alexander lehmann
- + I rewrote fread and fwrite to do CR/LF conversion when in text mode.
- + Additionally I fixed a small bug in eof detection.
- +
- + ( this pertains to the example when you are fread'ing say 20 bytes
- + from a file that contains 18 bytes: in the old coding
- + you would first succeeed with a count of 18, and on subsequent
- + freads you would get eof. In this coding, you get a count of 18
- + and also eof flag:
- + Well this was not really a bug, just when eof shows up. My ansiC
- + doc is mum on this point) -- ++jrb
- +
- + ---------------------------- Patchlevel 79 ---------------------------
- *** 1.54 1992/03/22 21:57:30
- --- PatchLev.h 1992/03/28 06:37:02
- ***************
- *** 1,5 ****
-
- ! #define PatchLevel "78"
-
- /*
- *
- --- 1,5 ----
-
- ! #define PatchLevel "79"
-
- /*
- *
- *** 1.9 1991/09/24 16:44:02
- --- console.c 1992/03/24 18:54:00
- ***************
- *** 36,43 ****
- } k_buf;
-
- k_buf in_buf[NUMDEV];
- - #define IN_BUF(dev) (&in_buf[(dev) > 2 ? _console_dev : (dev)])
-
- /*
- * what handle means:: 0-2: BIOS handle, 3: stdout, 4: stderr
- */
- --- 36,46 ----
- } k_buf;
-
- k_buf in_buf[NUMDEV];
-
- + #define in_dev(dev) ((dev)>2 ? _console_dev : (dev))
- +
- + #define IN_BUF(dev) (&in_buf[in_dev(dev)])
- +
- /*
- * what handle means:: 0-2: BIOS handle, 3: stdout, 4: stderr
- */
- ***************
- *** 44,49 ****
- --- 47,53 ----
- static short LOOKUP __PROTO((short handle));
- static long raw_in __PROTO((int dev));
- static long raw_instat __PROTO((int dev));
- + void flush_key_buff __PROTO((int dev));
- #if 0
- static void raw_out __PROTO((int dev, int c));
- #endif
- ***************
- *** 81,92 ****
- raw_in(dev)
- int dev;
- {
- ! if (dev < 3)
- ! return Bconin(dev);
- ! else if (dev == 3)
- ! return Crawcin();
- ! else
- ! return Cauxin();
- }
-
- #if 0
- --- 85,91 ----
- raw_in(dev)
- int dev;
- {
- ! return Bconin(in_dev(dev));
- }
-
- #if 0
- ***************
- *** 107,118 ****
- raw_instat(dev)
- int dev;
- {
- ! if (dev < 3)
- ! return Bconstat(dev);
- ! else if (dev == 3)
- ! return Cconis();
- ! else
- ! return Cauxis();
- }
-
- /*
- --- 106,112 ----
- raw_instat(dev)
- int dev;
- {
- ! return Bconstat(in_dev(dev));
- }
-
- /*
- ***************
- *** 165,208 ****
- int handle;
- int n;
- {
- - long c;
- - short i, j, waiting = 0;
- char ch;
- - k_buf *p;
- short dev;
-
- dev = LOOKUP(handle);
- - p = IN_BUF(dev);
-
- ! while (__check_signals && (raw_instat(dev) || waiting)) {
- ! c = raw_in(dev);
- ! if (!(__ttymode & RAW)) {
- ! ch = c & 0xff;
- ! if (ch == ('S'-'@')) {
- ! waiting = 1;
- ! }
- ! else if (ch == ('Q'-'@')) {
- ! waiting = 0;
- ! }
- ! else if (ch == __tchars[TC_INTRC]) {
- ! p->head = p->tail;
- ! raise(SIGINT);
- ! }
- ! else if (ch == __tchars[TC_QUITC]) {
- ! p->head = p->tail;
- ! raise(SIGQUIT);
- ! }
- ! else if (!waiting) {
- ! i = p->head;
- ! j = i + 1;
- ! if (j >= KBUFSIZ) j = 0;
- ! if (j != p->tail) {
- ! p->buffer[i] = c;
- ! p->head = j;
- ! }
- ! }
- ! }
- ! }
- /* raw_out(dev, n); */
- ch = n;
- (void)Fwrite(handle, 1L, &ch);
- --- 159,171 ----
- int handle;
- int n;
- {
- char ch;
- short dev;
-
- dev = LOOKUP(handle);
-
- ! if (__check_signals)
- ! flush_key_buff(dev);
- /* raw_out(dev, n); */
- ch = n;
- (void)Fwrite(handle, 1L, &ch);
- ***************
- *** 255,257 ****
- --- 218,221 ----
- }
- }
- }
- +
- *** 1.11 1992/03/22 21:57:30
- --- fread.c 1992/03/24 18:54:21
- ***************
- *** 1,4 ****
- ! /* nothing like the origonal from
- * from Dale Schumacher's dLibs
- */
-
- --- 1,4 ----
- ! /* nothing like the original from
- * from Dale Schumacher's dLibs
- */
-
- ***************
- *** 10,17 ****
- #include <string.h>
- #include "lib.h"
-
- ! size_t fread(data, size, count, fp)
- ! register void *data;
- size_t size;
- size_t count;
- register FILE *fp;
- --- 10,17 ----
- #include <string.h>
- #include "lib.h"
-
- ! size_t fread(_data, size, count, fp)
- ! void *_data;
- size_t size;
- size_t count;
- register FILE *fp;
- ***************
- *** 19,24 ****
- --- 19,26 ----
- register size_t n;
- register long l, cnt;
- register unsigned int f;
- + char *data=_data;
- + char *ptr;
-
- assert((data != NULL));
- assert((size != 0));
- ***************
- *** 35,40 ****
- --- 37,43 ----
- return 0;
- #endif
- assert((n <= (size_t)LONG_MAX));
- + if( f&_IOBIN ) {
- again:
- if((cnt = fp->_cnt) > 0)
- {
- ***************
- *** 62,77 ****
- }
- else
- { /* read in n bytes into data */
- ! if((cnt = _read(fp->_file, data, (unsigned long)n))<=0) {
- fp->_flag |= ((cnt == 0) ? _IOEOF : _IOERR);
- goto ret;
- }
- ! data+=cnt;
- ! l+=cnt;
- ! n-=cnt;
- ! goto again;
- }
- }
- ret:
- return((l > 0) ? ((size_t)l / size) : 0);
- }
- --- 65,133 ----
- }
- else
- { /* read in n bytes into data */
- ! if((cnt = _read(fp->_file, data, (unsigned long)n)) != n)
- ! { /* EOF or error */
- ! fp->_flag |= ((cnt >= 0) ? _IOEOF : _IOERR);
- ! }
- ! if( cnt>0 )
- ! l += cnt;
- ! }
- ! }
- ! } else {
- ! while( n>0 ) {
- ! if( (cnt=fp->_cnt)>0 ) {
- ! ptr=(char*)fp->_ptr;
- ! while( n>0 && cnt>0 ) {
- ! if( *ptr!='\r' ) {
- ! *data++=*ptr++;
- ! cnt--;
- ! n--;
- ! l++;
- ! } else {
- ! ptr++;
- ! cnt--;
- ! }
- ! }
- ! fp->_cnt=cnt;
- ! fp->_ptr=(unsigned char*)ptr;
- ! }
- ! if( n==0 ) break; /* done */
- ! /* wanna have n more bytes */
- ! if( n<fp->_bsiz ) {
- ! /* read in fp->_bsiz bytes into fp->_base and do it again */
- ! fp->_ptr = fp->_base;
- ! if((cnt = _read(fp->_file, fp->_base, (unsigned long)fp->_bsiz)) <= 0)
- ! { /* EOF or error */
- fp->_flag |= ((cnt == 0) ? _IOEOF : _IOERR);
- goto ret;
- }
- ! fp->_cnt = cnt;
- ! } else {
- ! /* read in n bytes into data */
- ! if((cnt = _read(fp->_file, data, (unsigned long)n)) != n)
- ! { /* EOF or error */
- ! fp->_flag |= ((cnt >= 0) ? _IOEOF : _IOERR);
- ! /* if EOF but read bytes still convert CRLF */
- ! if( cnt<=0 ) goto ret;
- ! }
- ! ptr=data;
- ! while( cnt>0 ) {
- ! if( *ptr!='\r' ) {
- ! *data++=*ptr++;
- ! cnt--;
- ! n--;
- ! l++;
- ! } else {
- ! ptr++;
- ! cnt--;
- ! }
- ! }
- ! if( fp->_flag&_IOEOF )
- ! goto ret;
- }
- }
- + }
- +
- ret:
- return((l > 0) ? ((size_t)l / size) : 0);
- }
- *** 1.10 1992/03/22 21:57:30
- --- fwrite.c 1992/03/24 18:54:27
- ***************
- *** 8,23 ****
- #include <string.h>
- #include "lib.h"
-
- ! size_t fwrite(data, size, count, fp)
- ! const register void *data;
- ! size_t size;
- ! size_t count;
- ! register FILE *fp;
- ! {
- register size_t n, m;
- register long l = 0;
- long space;
- unsigned int f = fp->_flag;
-
- if(f & _IORW)
- {
- --- 8,28 ----
- #include <string.h>
- #include "lib.h"
-
- ! size_t fwrite(_data, size, count, fp)
- ! const void *_data;
- ! size_t size;
- ! size_t count;
- ! register FILE *fp;
- ! {
- ! const char *data=_data;
- register size_t n, m;
- register long l = 0;
- long space;
- unsigned int f = fp->_flag;
- + const char *restart_buf;
- + int have_nl;
- + int wrote_cr;
- + int line_flush;
-
- if(f & _IORW)
- {
- ***************
- *** 34,69 ****
- n = count * size;
- assert ( n <= (size_t)LONG_MAX); /* otherwise impl will not work */
-
- ! space = fp->_bsiz - fp->_cnt;
- ! while(n > 0)
- ! {
- ! m = (n > space)? space: n;
- ! bcopy(data, fp->_ptr, m);
- ! fp->_ptr += m;
- ! fp->_cnt += m;
- ! space -= m;
- ! if(space == 0)
- ! {
- ! if(fflush(fp))
- return 0;
- ! space = fp->_bsiz;
- ! if(f & _IORW)
- ! fp->_flag |= _IOWRT; /* fflush resets this */
- ! }
- ! l += m;
- ! data = (char *)data + m;
- ! n -= m;
- ! if(n < space)
- ! continue;
- ! if((m = _write(fp->_file, data, (unsigned long)n))
- ! != (long)n)
- ! {
- ! fp->_flag |= _IOERR;
- ! return 0;
- ! }
- ! l += m;
- ! break;
- }
- !
- return((l > 0) ? ((size_t)l / size) : 0);
- ! }
- --- 39,138 ----
- n = count * size;
- assert ( n <= (size_t)LONG_MAX); /* otherwise impl will not work */
-
- ! if( f&_IOBIN ) {
- ! space = fp->_bsiz - fp->_cnt;
- ! while(n > 0)
- ! {
- ! m = (n > space)? space: n;
- ! bcopy(data, fp->_ptr, m);
- ! fp->_ptr += m;
- ! fp->_cnt += m;
- ! space -= m;
- ! if(space == 0)
- ! {
- ! if(fflush(fp))
- ! return 0;
- ! space = fp->_bsiz;
- ! if(f & _IORW)
- ! fp->_flag |= _IOWRT; /* fflush resets this */
- ! }
- ! l += m;
- ! data += m;
- ! n -= m;
- ! if(n < space)
- ! continue;
- ! if((m = _write(fp->_file, data, (unsigned long)n )) != (long)n)
- ! {
- ! fp->_flag |= _IOERR;
- ! return 0;
- ! }
- ! l += m;
- ! break;
- ! }
- ! } else {
- ! have_nl=1;
- ! wrote_cr=0;
- ! line_flush=0;
- ! /* this relies on having at least one byte buffer,
- ! otherwise we'll hang up when trying to write CRLF */
- ! while(n > 0)
- ! {
- ! space = fp->_bsiz - fp->_cnt;
- ! restart_buf=data;
- ! while( space>0 && n>0 ) {
- ! if( *data=='\n' ) {
- ! if( !wrote_cr ) {
- ! if( f&_IOLBF ) line_flush=1;
- ! *fp->_ptr++='\r';
- ! wrote_cr=1;
- ! have_nl=1;
- ! } else {
- ! *fp->_ptr++='\n';
- ! data++;
- ! wrote_cr=0;
- ! n--;
- ! }
- ! } else {
- ! *fp->_ptr++=*data++;
- ! n--;
- ! }
- ! space--;
- ! fp->_cnt++;
- ! l++;
- ! }
- !
- ! if( space==0 ) {
- ! if( have_nl ) {
- ! if(fflush(fp))
- ! return 0;
- ! if(f & _IORW)
- ! fp->_flag |= _IOWRT; /* fflush resets this */
- ! have_nl=0;
- ! } else {
- ! /* this will probably happen in nonbuffered mode only:
- ! try to write as much data in one go as possible */
- ! fp->_cnt=0;
- ! fp->_ptr=fp->_base;
- ! while( n && *data!='\n' ) {
- ! n--;
- ! data++;
- ! }
- ! if( (m=_write(fp->_file, restart_buf, data-restart_buf ))
- ! != data-restart_buf ) {
- ! fp->_flag |= _IOERR;
- return 0;
- ! }
- ! l+=m;
- ! }
- ! }
- ! }
- ! if( line_flush ) {
- ! if(fflush(fp))
- ! return 0;
- ! if(f & _IORW)
- ! fp->_flag |= _IOWRT; /* fflush resets this */
- ! }
- }
- !
- return((l > 0) ? ((size_t)l / size) : 0);
- ! }
- *** 1.6 1991/07/23 22:06:28
- --- signal.c 1992/03/24 18:54:36
- ***************
- *** 15,21 ****
- #include <unistd.h>
-
- extern int __check_signals; /* used in console i/o routines */
- ! #define SIG_EXIT 10 /* exit code */
-
- struct sigarray_str {
- __Sigfunc s_func;
- --- 15,21 ----
- #include <unistd.h>
-
- extern int __check_signals; /* used in console i/o routines */
- ! #define SIG_EXIT 10 /* exit code */
-
- struct sigarray_str {
- __Sigfunc s_func;
- ***************
- *** 40,49 ****
- case SIGINT:
- case SIGQUIT:
- if (func != SIG_IGN)
- ! __check_signals += 1;
- else
- ! __check_signals = (__check_signals == 1) ?
- ! 0 : --__check_signals;
- case SIGALRM:
- case SIGABRT:
- oldfunc = sig_array[sig].s_func;
- --- 40,49 ----
- case SIGINT:
- case SIGQUIT:
- if (func != SIG_IGN)
- ! __check_signals |= (sig==SIGINT ? 1 : 2);
- else
- ! __check_signals &= (sig==SIGINT ? ~1 : ~2);
- ! /* falltrough */
- case SIGALRM:
- case SIGABRT:
- oldfunc = sig_array[sig].s_func;
-